package org.pupil.rpc.tolerant;

import org.pupil.rpc.common.ServiceMeta;
import org.pupil.rpc.protocol.RpcResponse;

import java.util.Collection;

/**
 * 容错策略数据共享容器
 */
public class FaultTolerantStrategyShareContainer {

    private static FaultTolerantStrategyShareContainer instance;

    // 当前服务节点
    private ServiceMeta curServiceMeta;
    // 剩余的服务节点（空闲状态）
    private Collection<ServiceMeta> otherServiceMeta;
    // 重试次数
    private long count;
    // 错误信息
    private String errorMsg;
    // 服务名
    private String serviceName;
    // 响应消息
    private RpcResponse rpcResponse;
    // 记录是否有返回值
    private Boolean isReturnValue = false;
    // 返回值
    private Object returnValue;

    public FaultTolerantStrategyShareContainer() {
    }

    // 获取容错策略数据共享容器
    public static FaultTolerantStrategyShareContainer getInstance(){
        if (instance == null){
            instance = new FaultTolerantStrategyShareContainer();
        }
        return instance;
    }

    public RpcResponse getRpcResponse() {
        return rpcResponse;
    }

    public void setRpcResponse(RpcResponse rpcResponse) {
        this.rpcResponse = rpcResponse;
    }

    public Boolean getIsReturnValue() {
        return isReturnValue;
    }

    public void setIsReturnValue(Boolean isReturnValue) {
        this.isReturnValue = isReturnValue;
    }


    public Object getReturnValue(){
        return returnValue;
    }

    public void setReturnValue(Object returnValue) {
        this.returnValue = returnValue;
    }

    public ServiceMeta getCurServiceMeta() {
        return curServiceMeta;
    }

    public void setCurServiceMeta(ServiceMeta curServiceMeta) {
        this.curServiceMeta = curServiceMeta;
    }

    public Collection<ServiceMeta> getOtherServiceMeta() {
        return otherServiceMeta;
    }

    public void setOtherServiceMeta(Collection<ServiceMeta> otherServiceMeta) {
        this.otherServiceMeta = otherServiceMeta;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
}
